package com.whater.auth.client.rest.api;

import java.io.File;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.whater.auth.client.service.ImageService;
import com.whater.common.util.WxChatImgRevert2;

@Controller
@RequestMapping("image")
public class ImageController {
	
	@Autowired
	private ImageService imageService ;
	
	@RequestMapping("/show")
	public void show(HttpServletRequest request, HttpServletResponse response) throws Exception {
		response.setHeader("Pragma", "no-cache");
		response.setHeader("Cache-Control", "no-cache");
		response.setDateHeader("Expires", 0);
		response.setContentType("image/jpeg");
//		File file = new File("C:\\Users\\49271\\Desktop\\work\\wechart\\to\\b99aa6e2fc8d044a91bd5b07b5827801.jpg");
//		InputStream is = new FileInputStream(file);
//		BufferedImage bi = ImageIO.read(is);
//		ImageIO.write(bi, "JPEG", response.getOutputStream());
		File file = new File("C:\\Users\\49271\\Desktop\\work\\wechart\\from\\b99aa6e2fc8d044a91bd5b07b5827801.dat");
		WxChatImgRevert2.outImage( file, response.getOutputStream());
	}

	
	
	@RequestMapping("/item")
	public void item(HttpServletRequest request, HttpServletResponse response) throws Exception {
		response.setHeader("Pragma", "no-cache");
		response.setHeader("Cache-Control", "no-cache");
		response.setDateHeader("Expires", 0);
		response.setContentType("image/jpeg");
			String image = request.getParameter("image");
		String dir = request.getParameter("dir");
		File file = new File(imageService.getFullPath(dir+"/"+image));
		WxChatImgRevert2.outImage( file, response.getOutputStream());
	}
	
}
